//
//  CBattleSystem.cpp
//  Monster_Martial_Arts_Version_0
//
//  Created by bk on 13/1/5.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//

#include <iostream>

#include "CBattleSystem.h"
#include "CPlayerControl.h"
#include "CBattleManager.h"
#include "CPetObject.h"
#include "CMonsterObject.h"
//#include "CInputSystem.h"

CBattleSystem::CBattleSystem()
{
    m_PlayerCtr = NULL;
}

CBattleSystem::~CBattleSystem()
{
    if (m_PlayerCtr)
    {
        delete m_PlayerCtr;
        m_PlayerCtr = NULL;
    }
}

void CBattleSystem::Init()
{
     //1.Create PlayerControl
    
     m_PlayerCtr = new CPlayerControl();
    
     m_PlayerCtr->Init();
    
     
     //
    
    
}

void CBattleSystem::Update(float dt)
{
    CCNode* node = CBattleManager::Get().GetBattleLayer();
    
    TEAM team = CBattleManager::Get().GetTeam(BATTLE_TEAM_RED);
    
    TeamMemberIter pi = team.m_TeamMember.begin();
    
    //CBattleObject* obj = NULL;
    
    while (pi != team.m_TeamMember.end())
    {
        (*pi)->Update(node, dt);
        
        pi++;
    }
    
    TEAM blueteam = CBattleManager::Get().GetTeam(BATTLE_TEAM_BLUE);
    
    TeamMemberIter pi2 = blueteam.m_TeamMember.begin();
    
    //CBattleObject* obj = NULL;
    
    while (pi2 != blueteam.m_TeamMember.end())
    {
        (*pi2)->Update(node, dt);
        
        pi2++;
    }
}

void CBattleSystem::Start()
{
    CCNode* node = CBattleManager::Get().GetBattleLayer();
    
    CCAssert(node,"when Battle start , the BattleLayer can not NULL");
    
    //Create object
    CreatePlayerTeam(node);
    CreateMonsterTeam(node);
}

void CBattleSystem::Leave()
{
    
}

void CBattleSystem::CreatePlayerTeam(CCNode* pNode)
{
    CBattleManager::Get().AddTeamMember(BATTLE_TEAM_RED,CBattleObject::CreateObject<CPetObject>(pNode,testName,fPoint(PET_1_X_POS,PET_1_Y_POS)));
    
    
}

void CBattleSystem::CreateMonsterTeam(CCNode* pNode)
{
    //CMonsterObject
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    CBattleManager::Get().AddTeamMember(BATTLE_TEAM_BLUE,CBattleObject::CreateObject<CMonsterObject>(pNode,testName,fPoint(CMONSTER_1_X_POS,(rand()%((int)size.height)))));
    
}
